package com.heima.search.pojo;

import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.util.*;

@Data
@NoArgsConstructor
public class ItemDoc {
    private Long id;//商品id
    private String name;//商品名称
    private Long price;//价格（分）
    private Integer stock;//库存数量
    private String image;//商品图片
    private String category;//分类名称
    private String brand;//品牌名称
    private Integer sold;//销量
    private Integer commentCount;//评论数
    @TableField("isAD")
    private Boolean isAD;//是否是推广广告，true/false
    private Date updateTime;//更新时间
    private List<String> suggestion;//是将现有的字段放入 例如 商圈 品牌等，方便自动补全
 /*   3.将db转成doc
    com.hmall.common.dto.ItemDoc itemDoc = new com.hmall.common.dto.ItemDoc();
//                使用属性拷贝
                BeanUtils.copyProperties(item, itemDoc);
    //                设置suggestion搜索中自动补齐
    String brand = item.getBrand();
    String category = item.getCategory();
    String name = item.getName();
//                按照空格分隔name
                if (name.contains(" ")) {
        String[] strings = name.split(" ");
        List<String> listSuggestion = new ArrayList<>();
        listSuggestion.add(category);
        listSuggestion.add(brand);
        Collections.addAll(listSuggestion, strings);
        itemDoc.setSuggestion(listSuggestion);
    } else {
        itemDoc.setSuggestion(Arrays.asList(name, category, brand));
    }*/

}
